package com.czl.websocket.controller.innet;

import com.czl.websocket.server.ServerDemo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.UnknownHostException;

/**
 * @author 石雷
 * shilei1@jiayuan.com
 * 2021/1/20/020 18:12
 */

@RestController
@RequestMapping("/socket")
public class WebsocketController {

    @RequestMapping("/start")
    public String startSocketServer(){
        try {
            new ServerDemo(9898).start();
        } catch (UnknownHostException e) {
            return "启动失败";
        }
        return "启动成功";
    }

    @RequestMapping("/stop")
    public String stopSocketServer(){
        try {
            new ServerDemo(9898).stop();
        } catch (Exception e) {
            return "停止失败";
        }
        return "停止失败";
    }

}
